import 'package:basic_common/common_exports.dart';
import 'package:basic_common/global_getx.dart';

import '../../model/evaluate_data_list.dart';

class EvaluateController extends GetxController {
  final evaluateList = <EvaluateData>[].obs;
  TextEditingController replyController = TextEditingController();

  /// 获取评价列表
  void getEvaluateList() async {
    evaluateList.value=[];
    HttpData res = await ApiService().getEvaluateList(data: {
      "doctorNo": globalGetx.doctorInfo!.doctorNo!,
      "serviceStatus": ""
    });
    if (res.code == 1) {
      List eListData = res.data;
      if (eListData.length > 0) {
        eListData.forEach((element) {
          EvaluateData evaluateData = EvaluateData.fromJson(element);
          evaluateList.add(evaluateData);
        });
      }
    }
    update(['evaluateList']);
  }

  /// 回复

  void addReply({required int replyId}) async {
    String content = replyController.text;
    if (content.isEmpty) {
      return ToastUtils.toast("回复内容不能为空");
    }
    HttpData res =
        await ApiService().replyEvaluate(data: {"id": replyId.toString(), "reply": content});
    if (res.code == 1) {
      ToastUtils.toast("回复成功");
      getEvaluateList();
    } else {
      ToastUtils.toast("回复失败");
    }
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getEvaluateList();
  }
}
